import type { FieldRule } from 'vant'

// 1. 手机号校验
const mobileRules: FieldRule[] = [
  { required: true, message: '手机号不能为空' },
  { pattern: /^1[3-9]\d{9}$/, message: '手机号格式不正确' }
]

// 2. 密码校验
const passwordRules: FieldRule[] = [
  { required: true, message: '密码不能为空' },
  { pattern: /^\w{8,24}$/, message: '密码长度在8-24个字符' }
]

// 3. 短信验证码校验
const codeRules: FieldRule[] = [
  { required: true, message: '验证码不能为空' },
  { pattern: /^\d{6}$/, message: '验证码为6位数字' }
]

// 4. 姓名校验
const nameRules: FieldRule[] = [
  { required: true, message: '姓名不能为空' },
  // 2-18位中文字符
  { pattern: /^[\u4e00-\u9fa5]{2,18}$/, message: '中文2-18个字符' }
]

// 5. 身份证校验
const idcardRules: FieldRule[] = [
  { required: true, message: '身份证不能为空' },
  {
    pattern:
      /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/,
    message: '身份证号不正确'
  }
]

export { mobileRules, passwordRules, codeRules, nameRules, idcardRules }
